home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group97b.txt / 000137_icon-group-sender _Fri Dec 12 07:44:29 1997.msg < prev    next >
Internet Message Format  |  2000-09-20  |  4KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id HAA07416
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Fri, 12 Dec 1997 07:44:29 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA11776; Fri, 12 Dec 1997 07:44:28 -0700
  7. Date: Thu, 11 Dec 97 22:18:02 -0500
  8. Message-Id: <9712120318.AA0094@valinet.com>
  9. From: Paul Abrahams <abrahams@acm.org>
  10. To: icon-group@optima.CS.Arizona.EDU
  11. Cc: abrahams@acm.org (Paul Abrahams)
  12. Subject: Extensions to `open'
  13. Reply-To: abrahams@acm.org
  14. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  15. Status: RO
  16.  
  17. I would like to propose a small but very useful extension to Icon: that
  18. it should be possible to open a directory by specifying a "d" option to
  19. the `open' function.
  20.  
  21. It seems that any extension to Icon ought to satisfy three criteria:
  22.   (1) It provides functionality that isn't easily achieved by other means.
  23.   (2) It is stylistically consistent with the rest of the language and
  24. won't break existing code,.
  25.   (3) For a minor extension, it should take someone familiar with the
  26. implementation no more than half a day to code.  (Testing and debugging,
  27. of course, has to be added on.)
  28.  
  29. Icon already recognizes the existence of directories by providing the
  30. "chdir" function.  At first glance it would seem that being able to scan
  31. a directory is easy enough with the `system' function: you just call the
  32. system command for the purpose.  But that approach has two difficulties.
  33.  
  34. It's very awkward to retrieve the output, since `system' returns only an
  35. exit code.  More significantly, the user code depends unnecessarily on
  36. the operating environment: in Unix you use `ls', in DOS/Windows you use
  37. `dir', and in MacOS you use something else again which I don't know.
  38. Yet directory structure is a concept common to all modern operating
  39. systems.  It ought to be possible to read a directory without having to
  40. resort to system-dependent code.
  41.  
  42. Adding an option letter to the second argument of `open' is clearly
  43. consistent with Icon as it stands.  The associated file would then act
  44. as a generator whose result sequence consists of the names of the files
  45. in the directory.  `read' would produce the next file name in the
  46. directory; `reads' should probably produce an error when called on a
  47. directory (as it does, I believe, when called on an output file).
  48.  
  49. As to the work involved: although I don't know the actual code, I assume
  50. that it involves going to the place where the option letters are
  51. extracted for `open' and inserting one additional case, together with the
  52. appropriate system call.  It also involves recording the fact that the
  53. file is a directory.  In the code for `read', it involves substituting
  54. the "get next filename" API for the "read line" API; both Unix and DOS
  55. provide such an API.
  56.  
  57. -------
  58.  
  59. Then there's another extension, perhaps even more useful but not quite
  60. as straightforward to implement: if `open' is called with a null
  61. argument, it invokes the current system's API for *dynamically*
  62. selecting a file to be opened.  This is the usual dialog that enables a
  63. user to browse the directory structure, looking for the file to be
  64. opened.  I have a hunch that if graphical user interfaces were common in
  65. the days when Ralph was first designing Icon, he would have included
  66. this facility.  It recognizes that programs are now used in far more
  67. interactive environments than they were in the old days.
  68.  
  69. Paul Abrahams
  70.  
  71.